/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package desktopapplication1;

//Color each row in a JTable
import bean.ConsultaCita;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.table.*;

class ColorRenderer extends JLabel implements TableCellRenderer {

    private String columnName;
    private ArrayList<ConsultaCita> pacientesxDia;

    public ColorRenderer(String column, ArrayList<ConsultaCita> pacientesxDia) {
        this.columnName = column;
        this.pacientesxDia = pacientesxDia;
        setOpaque(true);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Object columnValue = table.getValueAt(row, table.getColumnModel().getColumnIndex(columnName));

        if (value != null) {
            setText(value.toString());
        }
        if (isSelected) {
            setBackground(table.getSelectionBackground());
            setForeground(table.getSelectionForeground());
        } else {
            setBackground(table.getBackground());
            setForeground(table.getForeground());
            if (estaEvaluado(pacientesxDia, columnValue.toString())) {

                    setBackground(java.awt.Color.ORANGE);

            }
//
//             if (columnValue.equals("Cardona")) setBackground(java.awt.Color.pink);
//             if (columnValue.equals("Galeano")) setBackground(java.awt.Color.green);
//
//             if (columnValue.equals("Restrepo")) setBackground(java.awt.Color.blue);

        }
        return this;
    }

    private boolean estaEvaluado(ArrayList<ConsultaCita> pacientesxDia, String idUsuario) {

        for (int i = 0; i < pacientesxDia.size(); i++) {
            if (pacientesxDia.get(i).getIdUsuario().equals(idUsuario)) {
/*
                if (pacientesxDia.get(i).getTipo().equals("1")) {
                    return true;
                } else {
                    return false;
                }
*/
                return true;
            }
        }
        return false;
    }
}
